package com.belazy.library.util.compute;

import com.belazy.library.util.constant.RegexConstant;
import org.springframework.util.StringUtils;

import java.util.regex.Pattern;

/**
 * @Description <p> 校验数据格式工具类</p>
 * @Author chupeng.tang
 * @CreateTime 2023/5/19 17:29
 * @Version 1.0
 */
public class ValidateUtils {
    /**
     * <p>验证邮箱</p>
     * @auhor chupeng.tang
     * @datetime 2023/5/20 11:52
     * @param: email
     * @return {@link boolean}
     **/
    public static boolean validateEmail(String email) {
        if (StringUtils.isEmpty (email)) {
            return false;
        }
        return Pattern.matches (RegexConstant.EMAIL, email);
    }
    /**
     * <p>验证手机号</p>
     * @auhor chupeng.tang
     * @datetime 2023/5/20 11:52
     * @param: phone
     * @return {@link boolean}
     **/
    public static boolean validatePhone(String phone) {
        if (StringUtils.isEmpty (phone)) {
            return false;
        }
        return Pattern.matches (RegexConstant.PHONE_CHINA_TELECOM, phone) || Pattern.matches (RegexConstant.PHONE_CHINA_UNION, phone) || Pattern.matches (RegexConstant.PHONE_CHINA_MOBILE, phone);
    }
    /**
     * <p>检测身份证格式是否正确</p>
     * @auhor chupeng.tang
     * @datetime 2023/5/20 11:53
     * @param: cardId
     * @return {@link boolean}
     **/
    public static boolean validateCardId(String cardId) {
        if (StringUtils.isEmpty (cardId)) {
            return false;
        }
        return Pattern.matches (RegexConstant.CARD_ID, cardId);
    }
    /**
     * <p>验证字符串是否是中文</p>
     * @auhor chupeng.tang
     * @datetime 2023/5/20 11:54
     * @param: chinaText
     * @return {@link boolean}
     **/
    public static boolean validateChineseText(String chinaText) {
        if (StringUtils.isEmpty (chinaText)) {
            return false;
        }
        return Pattern.matches (RegexConstant.CHINA_TEXT, chinaText);
    }
    /**
     * <p>验证非零的正整数</p>
     * @auhor chupeng.tang
     * @datetime 2023/5/20 11:54
     * @param: str
     * @return {@link boolean}
     **/
    public static boolean validateNonZeroPositiveInteger(String str) {
        java.util.regex.Matcher match = RegexConstant.PATTERN.matcher (str);
        if (match.matches () == false) {
            return false;
        } else {
            return true;
        }
    }
    /**
     * <p>验证是否为所要求的金额类型</p>
     * @auhor chupeng.tang
     * @datetime 2023/5/20 11:54
     * @param: str
     * @return {@link boolean}
     **/
    public static boolean validateCurrency(String str) {
        java.util.regex.Matcher match = RegexConstant.PATTERN_SENCOND.matcher (str);
        if (match.matches () == false) {
            return false;
        } else {
            return true;
        }
    }
    /**
     * <p>密码格式不能是纯字母或纯数字</p>
     * @auhor chupeng.tang
     * @datetime 2023/5/20 11:54
     * @param: str
     * @return {@link boolean}
     **/
    public static boolean validatePassword(String str) {
        if (str.matches (RegexConstant.NUMBER) || str.matches (RegexConstant.LETTER)) {
            return false;
        }
        return true;
    }
}
